"""
状态 枚举类
"""

from utils.enum_utils.base import IntegerEnum


class HTTPStatusCode(IntegerEnum):
    """
    HTTP 响应状态码 枚举类

    Be modeled after -> `rest_framework.status`
    """

    # 消息 - 请求已被服务器接收，继续处理
    HTTP_100_CONTINUE = 100, "Continue | 请继续请求"
    HTTP_101_SWITCHING_PROTOCOLS = 101, "Switching Protocols | 协议切换中"
    HTTP_102_PROCESSING = 102, "Processing | 请求处理中"
    HTTP_103_EARLY_HINTS = 103, "Early Hints | 早期提示"

    # 成功 - 请求已成功被服务器接收、理解、并接受
    HTTP_200_OK = 200, "OK | 正常"
    HTTP_201_CREATED = 201, "Created | 资源创建成功"
    HTTP_202_ACCEPTED = 202, "Accepted | 请求已接受"
    HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203, "Non Authoritative Information | 非官方信息"
    HTTP_204_NO_CONTENT = 204, "No Content | 资源删除成功"
    HTTP_205_RESET_CONTENT = 205, "Reset Content | 重置内容"
    HTTP_206_PARTIAL_CONTENT = 206, "Partial Content | 局部内容"
    HTTP_207_MULTI_STATUS = 207, "Multi Status | 多个状态"
    HTTP_208_ALREADY_REPORTED = 208, "Already Reported | 成员已经在"
    HTTP_226_IM_USED = 226, "Im Used | 资源正在被使用"

    # 重定向 - 需要后续操作才能完成这一请求
    HTTP_300_MULTIPLE_CHOICES = 300, "Multiple Choices | 多重选择"
    HTTP_301_MOVED_PERMANENTLY = 301, "Moved Permanently | 永久移动到新位置"
    HTTP_302_FOUND = 302, "Found | 资源已找到"
    HTTP_303_SEE_OTHER = 303, "See Other | 参考其他信息"
    HTTP_304_NOT_MODIFIED = 304, "Not Modified | 资源未被修改"
    HTTP_305_USE_PROXY = 305, "Use Proxy | 使用代理"
    HTTP_306_SWITCH_PROXY = 306, "Switch Proxy | 后续请求应使用指定的代理"
    HTTP_307_TEMPORARY_REDIRECT = 307, "Temporary Redirect | 临时重定向"
    HTTP_308_PERMANENT_REDIRECT = 308, "Permanent Redirect | 永久重定向"

    # 请求错误
    HTTP_400_BAD_REQUEST = 400, "Bad Request | 请求错误"
    HTTP_401_UNAUTHORIZED = 401, "Unauthorized | 未认证"
    HTTP_402_PAYMENT_REQUIRED = 402, "Payment Required | 请支付"
    HTTP_403_FORBIDDEN = 403, "Forbidden | 禁止访问"
    HTTP_404_NOT_FOUND = 404, "Not Found | 资源未找到"
    HTTP_405_METHOD_NOT_ALLOWED = 405, "Method Not Allowed | 请求方式不允许"
    HTTP_406_NOT_ACCEPTABLE = 406, "Not Acceptable | 无法访问"
    HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407, "Proxy Authentication Required | 需要代理身份验证"
    HTTP_408_REQUEST_TIMEOUT = 408, "Request Timeout | 请求超时"
    HTTP_409_CONFLICT = 409, "Conflict | 请求存在冲突"
    HTTP_410_GONE = 410, "Gone | 资源不再可用"
    HTTP_411_LENGTH_REQUIRED = 411, "Length Required | 需要数据长度"
    HTTP_412_PRECONDITION_FAILED = 412, "Precondition Failed | 先决条件错误"
    HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413, "Request Entity Too Large | 请求实体过大"
    HTTP_414_REQUEST_URI_TOO_LONG = 414, "Request Uri Too Long | 请求URI过长"
    HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415, "Unsupported Media Type | 不支持的媒体格式"
    HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416, "Requested Range Not Satisfiable | 请求范围无法满足"
    HTTP_417_EXPECTATION_FAILED = 417, "Expectation Failed | 预期结果失败"
    HTTP_418_IM_A_TEAPOT = 418, "Im A Teapot | 我是茶壶？！"
    HTTP_420_ENHANCE_YOUR_CAIM = 420, "Enhance Your Caim | 客户端被限速"  # noqa
    HTTP_422_UN_PROCESSABLE_ENTITY = 422, "Unprocessable Entity | 无法处理的实体"  # noqa
    HTTP_423_LOCKED = 423, "Locked | 资源已锁定"
    HTTP_424_FAILED_DEPENDENCY = 424, "Failed Dependency | 依赖失败"
    HTTP_425_UNORDERED_COLLECTION = 425, "Unordered Collection | 无序集合"
    HTTP_426_UPGRADE_REQUIRED = 426, "Upgrade Required | 需要升级"
    HTTP_428_PRECONDITION_REQUIRED = 428, "Precondition Required | 需要先决条件"
    HTTP_429_TOO_MANY_REQUESTS = 429, "Too Many Requests | 请求过于频繁"
    HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, "Request Header Fields Too Large | 请求头字段过长"
    HTTP_444_NO_RESPONSE = 444, "No Response | 无响应"
    HTTP_450_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450, "Blocked by Windows Parental Controls | 被Windows阻止"
    HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS = 451, "Unavailable For Legal Reasons | 因法律原因不可用"
    HTTP_494_REQUEST_HEADER_TOO_LARGE = 494, "Request Header Too Large | 请求头过长"

    # 服务器错误
    HTTP_500_INTERNAL_SERVER_ERROR = 500, "Internal Server Error | 服务器内部错误"
    HTTP_501_NOT_IMPLEMENTED = 501, "Not Implemented | 未实现"
    HTTP_502_BAD_GATEWAY = 502, "Bad Gateway | 网关错误"
    HTTP_503_SERVICE_UNAVAILABLE = 503, "Service Unavailable | 服务不可用"
    HTTP_504_GATEWAY_TIMEOUT = 504, "Gateway Timeout | 网关超时"
    HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505, "HTTP Version Not Supported | HTTP版本不支持"
    HTTP_506_VARIANT_ALSO_NEGOTIATES = 506, "Variant Also Negotiates | 内部配置错误"
    HTTP_507_INSUFFICIENT_STORAGE = 507, "Insufficient Storage | 存储空间不足"
    HTTP_508_LOOP_DETECTED = 508, "Loop Detected | 检测到死循环"
    HTTP_509_BANDWIDTH_LIMIT_EXCEEDED = 509, "Bandwidth Limit Exceeded | 超出带宽限制"
    HTTP_510_NOT_EXTENDED = 510, "Not Extended | 未扩展"
    HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required | 需要网络身份验证"

    @staticmethod
    def get_zh_label(enum: "HTTPStatusCode") -> str:
        """
        获取中文标签

        Args:
            enum (HTTPStatusCode): 枚举

        Returns:
            str: 中文标签
        """

        _, cn_label = enum.label.split(" | ")

        return cn_label

    @staticmethod
    def get_en_label(enum: "HTTPStatusCode") -> str:
        """
        获取英文标签

        Args:
            enum (HTTPStatusCode): 枚举

        Returns:
            str: 英文标签
        """

        en_label, _ = enum.label.split(" | ")

        return en_label

    @property
    def label_zh(self) -> str:
        """ 标签（中文） """

        return self.label.split(" | ")[-1]

    @property
    def label_en(self) -> str:
        """ 标签（英文） """

        return self.label.split(" | ")[0]
